<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        input {
            width: 600px;
            height: 40px;
            display: block;
            margin: 100px auto 0;
            font-size: 20px;
        }
        .box {
            text-align: center;
            width: 100px;
            height: 100px;
            background-color: #ccc;
            line-height: 100px;
            margin: 20px auto 0;
        }
    </style>
</head>
<body>
    <h3>代码被频繁执行</h3>
    <input type="text">
    <div class="box box-1">0</div>
    <div class="box box-2">0</div>
    <script>

        // 监听输入框的值变化
        document.querySelector("input[type='text']").oninput = function(){
            // 获取输入的值
            var v1 = this.value;
            // 假设请求数据
            getData(v1);
        }

        // 请求数据的函数
        function getData(val){
            console.log("输入的值:"+val);
        }


        // 窗口事件 
        var count = 0;
        window.onresize = function(){
            count ++;
            document.querySelector(".box-1").innerText = count;
        }


        // 鼠标移动事件
        var key = 0;
        document.onmousemove = function(){
            key ++;
            document.querySelector(".box-2").innerText = key;
        }
    </script>
</body>
</html>